package com.weng.sso.sdk.utils;


import java.util.Properties;

/**
 * 读取redis配置文件工具类
 * @author wengzhonghui
 */
public class SsoPropertiesUtil {
    private static Properties props;
    private static String SSO_SERVER_URL = "sso.server.url";
    private static String SSO_SECRET_APP_ID = "sso.client.appId";
    private static String SSO_SECRET_APP_SECRET = "sso.secret.key";
    private static String SSO_TIMEOUT_SECONDS = "request.timeout.seconds";
    private static PropertiesBean proCommon = null;

    static {
        try {
             proCommon = new PropertiesBean("sso-config.properties");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String getAppId() {
        return proCommon.getProp(SSO_SECRET_APP_ID);
    }

    public static String getAppSecret() {
        return proCommon.getProp(SSO_SECRET_APP_SECRET);
    }

    public static String getServerUrl() {
        return proCommon.getProp(SSO_SERVER_URL);
    }

    public static int getRequestTimeout() {
        String val =  proCommon.getProp(SSO_TIMEOUT_SECONDS);
        if(val!=null && !"".equalsIgnoreCase(val.trim())){
            return Integer.parseInt(val);
        }else{
            return 10*3600;
        }
    }


    public static String getProperty(String prop) {
        if (props != null) {
            return props.getProperty(prop);
        }
        return "";
    }

    public static int getIntProperty(String prop) {
        try {
            if (props != null) {
                return Integer.valueOf(props.getProperty(prop));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

}
